const express = require("express")
const router = express.Router()
const { searchMusic,deleteMusic } = require("../control/music")
const { SuccessModel, ErrorModel } = require("../model/resModel")

router.post("/search", async (req, res) => {
  let data = await searchMusic(req, res)
  if (data.length > 0) {
    res.json(new SuccessModel(data, "查找成功"))
  } else {
    res.json(new ErrorModel("查找失败"))
  }
})
router.post("/del", async (req, res) => {
  let data = await deleteMusic(req, res)
  if (data && data.affectedRows > 0) {
    res.json(new SuccessModel("删除成功"))
  } else {
    res.json(new ErrorModel("删除失败"))
  }
})

module.exports = router